#include <amxmodx>
#include <fun>
#include <rpgx>

#define MIN_ALPHA 25

new upgrade_id;

public plugin_init()
	register_plugin("Stealth RPGx Upgrade", "2.0", "roflmao456");

public RPGx_OnPluginReady()
	upgrade_id = RPGx_MakeUpgrade("Stealth", 5, 15, 10);

public RPGx_OnPlayerSpawn(id)
	SetStealth(id);

public RPGx_OnUpgradePurchase(id, upgrade, newlevel){
	if(upgrade == upgrade_id)
		SetStealth(id);
	}

public RPGx_OnUpgradeSell(id, upgrade, newlevel){
	if(upgrade == upgrade_id)
		SetStealth(id);
	}

SetStealth(id){
	new level = RPGx_GetUpgradeLevel(id, upgrade_id);
	if(level){
		new newalpha = floatround((255 / RPGx_GetUpgradeMaxLevel(upgrade_id)) * ((float(RPGx_GetUpgradeMaxLevel(upgrade_id)) - float(level))));
		if(newalpha < MIN_ALPHA)
			newalpha = MIN_ALPHA;
		set_user_rendering(id, kRenderFxNone, 0, 0, 0, kRenderTransAlpha, newalpha);
		} else {
		set_user_rendering(id);
		}
	}